package cn.edu.sgu.www.mhxysy.controller.equipment;

import cn.edu.sgu.www.mhxysy.pager.Pager;
import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.equipment.EquipmentTexiaoDTO;
import cn.edu.sgu.www.mhxysy.entity.equipment.EquipmentTexiao;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.equipment.EquipmentTexiaoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "装备特效管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/equipment_texiao", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class EquipmentTexiaoController {

	private final EquipmentTexiaoService equipmentTexiaoService;

	@Autowired
	public EquipmentTexiaoController(EquipmentTexiaoService equipmentTexiaoService) {
		this.equipmentTexiaoService = equipmentTexiaoService;
	}

	@ApiOperation("添加装备特效")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated EquipmentTexiaoDTO equipmentTexiaoDTO) {
		equipmentTexiaoService.insert(equipmentTexiaoDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID修改装备特效")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated EquipmentTexiaoDTO equipmentTexiaoDTO) {
		equipmentTexiaoService.updateById(equipmentTexiaoDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("查询全部装备特效")
	@RequestMapping(value = "/selectAll", method = RequestMethod.GET)
	public JsonResult<List<EquipmentTexiao>> selectAll() {
		List<EquipmentTexiao> list = equipmentTexiaoService.selectAll();

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过ID查询装备特效")
	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
	public JsonResult<EquipmentTexiao> selectById(
			@ApiParam(name = "id", value = "装备特效ID", required = true)
			@NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
		EquipmentTexiao equipmentTexiao = equipmentTexiaoService.selectById(id);

		return JsonResult.success(null, equipmentTexiao);
	}

	@ApiOperation("分页查询装备特效列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
	public JsonResult<JsonPage<EquipmentTexiao>> selectByPage(Pager<EquipmentTexiao> pager) {
		Page<EquipmentTexiao> page = equipmentTexiaoService.selectByPage(pager);

		return JsonResult.restPage(page);
	}

}